package com.breeze.webview.commands;

import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;

import com.breeze.base.BaseApplication;
import com.breeze.webview.IWebViewProcessCallbackInterface;
import com.breeze.webview.command.WebViewCommand;
import com.google.auto.service.AutoService;

import java.util.Map;

@AutoService(WebViewCommand.class)
public class ToastCommand implements WebViewCommand {
    @Override
    public String name() {
        return "showToast";
    }

    @Override
    public void execute(Map<String, String> params, IWebViewProcessCallbackInterface callback) {
        String message = params.get("message");
        // Toast所在线程必须支持Looper,这里使其在主线程运行即可.
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(() -> {
            Toast.makeText(BaseApplication.sApplication, message, Toast.LENGTH_SHORT).show();
        });
    }

}
